define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/devicelog/index',
                    add_url: 'jdy/devicelog/add',
                    edit_url: 'jdy/devicelog/edit',
                    del_url: 'jdy/devicelog/del',
                    multi_url: 'jdy/devicelog/multi',
                    table: 'jdy_devicelog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: true,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        //{field: 'id', title: __('Id')},
                        //{field: 'device_id', title: __('Device_id')},
                        {field: 'device.name', title: __('Device.name')},
                        {field: 'online', title: __('Online')},
                        {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'device.id', title: __('Device.id')},
                        //{field: 'device.room_id', title: __('Device.room_id')},
                        //{field: 'device.smallcategory_id', title: __('Device.smallcategory_id')},
                        //{field: 'device.deviceid', title: __('Device.deviceid')},
                        //{field: 'device.category', title: __('Device.category')},
                        //{field: 'device.type', title: __('Device.type')},
                        //{field: 'device.pid', title: __('Device.pid')},
                        //{field: 'device.name', title: __('Device.name')},
                        //{field: 'device.selfname', title: __('Device.selfname')},
                        //{field: 'device.place', title: __('Device.place')},
                        //{field: 'device.version', title: __('Device.version')},
                        //{field: 'device.online', title: __('Device.online')},
                        //{field: 'device.iconVer', title: __('Device.iconver')},
                        //{field: 'device.iconUrl', title: __('Device.iconurl'), formatter: Table.api.formatter.url},
                        //{field: 'device.center', title: __('Device.center')},
                        //{field: 'device.deviceIp', title: __('Device.deviceip')},
                        //{field: 'device.routeMacString', title: __('Device.routemacstring')},
                        //{field: 'device.subType', title: __('Device.subtype')},
                        //{field: 'device.state', title: __('Device.state')},
                        //{field: 'device.updatenum', title: __('Device.updatenum')},
                        //{field: 'device.online_starttime', title: __('Device.online_starttime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'device.create_time', title: __('Device.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'device.update_time', title: __('Device.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});